package com.shujia.jinjie;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PhoenixJDBC {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        //创建phoenix连接对象
        Connection conn = DriverManager.getConnection("jdbc:phoenix:master,node1,node2:2181");

        //获取数据库操作对象
        PreparedStatement prepared = conn.prepareStatement("select /*+ INDEX(DIANXIN DIANXIN_LOCAL_IDEX) */ grid_id,county from dianxin where grid_id=?");

        prepared.setString(1,"100160025685040");

        ResultSet resultSet = prepared.executeQuery();

        while (resultSet.next()){
            String gridId = resultSet.getString(1);
            String county = resultSet.getString(2);
            System.out.println(gridId+","+county);
        }

        conn.close();


    }
}
